#pragma once
#include "Control.hpp"
namespace NAMESPACENAME
{
	namespace DirectX
	{
		class DXGISwapChain;
		class D3D12CommandQueue;
	}
	class DirectXViewerControl :
		public Control
	{
	public:
		static const UINT nFrameBackBufCount = 3u;
	protected:
		UINT nFrameIndex = 0;
		UINT nFrame = 0;
		UINT nDXGIFactoryFlags = 0U;
		UINT nRTVDescriptorSize = 0U;
		float fAspectRatio = 3.0f;
		Microsoft::WRL::ComPtr<IDXGIFactory7>                pIDXGIFactory;
		Microsoft::WRL::ComPtr<IDXGIAdapter4>                pIAdapter;
		Microsoft::WRL::ComPtr<ID3D12Device9>                pID3DDevice;
		Microsoft::WRL::ComPtr<ID3D12CommandQueue>           pICommandQueue;
		Microsoft::WRL::ComPtr<IDXGISwapChain4>              pISwapChain[2];
		Microsoft::WRL::ComPtr<ID3D12DescriptorHeap>         pIRTVHeap;
		Microsoft::WRL::ComPtr<ID3D12Resource2>              pIARenderTargets[nFrameBackBufCount];
		Microsoft::WRL::ComPtr<ID3D12CommandAllocator>       pICommandAllocator;
		Microsoft::WRL::ComPtr<ID3D12RootSignature>          pIRootSignature;
		Microsoft::WRL::ComPtr<ID3D12PipelineState>          pIPipelineState;
		Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList6>   pICommandList;
		Microsoft::WRL::ComPtr<ID3D12Resource2>              pIVertexBuffer;
		Microsoft::WRL::ComPtr<ID3D12Fence1>                 pIFence;

		NAMESPACENAME::DirectX::DXGISwapChain* swapChain;
		NAMESPACENAME::DirectX::D3D12CommandQueue* commandQueue;
	public:
		DirectXViewerControl(const Rectangle& rect, String title, ContainerControl* parent = nullptr);
		static bool Initialize(bool enableDebug);
		bool CreateSwapChain(
			const DXGI_SWAP_CHAIN_DESC1* pDesc,
			const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullScreenDesc,
			IDXGIOutput* pRestrictToOutput
		);
		bool CreateCommandQueue(const D3D12_COMMAND_QUEUE_DESC* pDesc);
	};
}